

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>mindspore.dataset.SequentialSampler &mdash; MindSpore master documentation</title>
  

  
  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/language_data.js"></script>
        <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="mindspore.dataset.SubsetRandomSampler" href="mindspore.dataset.SubsetRandomSampler.html" />
    <link rel="prev" title="mindspore.dataset.RandomSampler" href="mindspore.dataset.RandomSampler.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../index.html" class="icon icon-home"> MindSpore
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">MindSpore Python API</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../mindspore.html">mindspore</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.common.initializer.html">mindspore.common.initializer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.communication.html">mindspore.communication</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.compression.html">mindspore.compression</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.context.html">mindspore.context</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../mindspore.dataset.html">mindspore.dataset</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id1">视觉</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id2">文本</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id3">音频</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id4">标准格式</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id5">用户自定义</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id6">图</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../mindspore.dataset.html#id7">采样器</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.DistributedSampler.html">mindspore.dataset.DistributedSampler</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.PKSampler.html">mindspore.dataset.PKSampler</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.RandomSampler.html">mindspore.dataset.RandomSampler</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">mindspore.dataset.SequentialSampler</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.SubsetRandomSampler.html">mindspore.dataset.SubsetRandomSampler</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.SubsetSampler.html">mindspore.dataset.SubsetSampler</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.dataset.WeightedRandomSampler.html">mindspore.dataset.WeightedRandomSampler</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.dataset.html#id8">其他</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.audio.html">mindspore.dataset.audio</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.config.html">mindspore.dataset.config</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.text.html">mindspore.dataset.text</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.transforms.html">mindspore.dataset.transforms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.vision.html">mindspore.dataset.vision</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.mindrecord.html">mindspore.mindrecord</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.html">mindspore.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.probability.html">mindspore.nn.probability</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.transformer.html">mindspore.nn.transformer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.numpy.html">mindspore.numpy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.ops.html">mindspore.ops</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.parallel.html">mindspore.parallel</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.parallel.nn.html">mindspore.parallel.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.profiler.html">mindspore.profiler</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.scipy.html">mindspore.scipy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.train.html">mindspore.train</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.boost.html">mindspore.boost</a></li>
</ul>
<p class="caption"><span class="caption-text">MindSpore C++ API</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html">MindSpore Lite↗</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">MindSpore</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../index.html" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../mindspore.dataset.html">mindspore.dataset</a> &raquo;</li>
        
      <li>mindspore.dataset.SequentialSampler</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../../_sources/api_python/dataset/mindspore.dataset.SequentialSampler.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="mindspore-dataset-sequentialsampler">
<h1>mindspore.dataset.SequentialSampler<a class="headerlink" href="#mindspore-dataset-sequentialsampler" title="Permalink to this headline">¶</a></h1>
<dl class="class">
<dt id="mindspore.dataset.SequentialSampler">
<em class="property">class </em><code class="sig-prename descclassname">mindspore.dataset.</code><code class="sig-name descname">SequentialSampler</code><span class="sig-paren">(</span><em class="sig-param">start_index=None</em>, <em class="sig-param">num_samples=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.SequentialSampler" title="Permalink to this definition">¶</a></dt>
<dd><p>按数据集的读取顺序采样数据集样本，相当于不使用采样器。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>start_index</strong> (int, 可选): 采样的起始样本ID，默认值：None，从数据集第一个样本开始采样。</p></li>
<li><p><strong>num_samples</strong> (int, 可选): 获取的样本数，可用于部分获取采样得到的样本。默认值：None，获取采样到的所有样本。</p></li>
</ul>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>TypeError</strong> <cite>start_index</cite> 不是整数值。</p></li>
<li><p><strong>TypeError</strong> <cite>num_samples</cite> 不是整数值。</p></li>
<li><p><strong>RuntimeError</strong> <cite>start_index</cite> 为负值。</p></li>
<li><p><strong>ValueError</strong> <cite>num_samples</cite> 为负值。</p></li>
</ul>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># creates a SequentialSampler</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sampler</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">SequentialSampler</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">ImageFolderDataset</span><span class="p">(</span><span class="n">image_folder_dataset_dir</span><span class="p">,</span>
<span class="gp">... </span>                                <span class="n">num_parallel_workers</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span>
<span class="gp">... </span>                                <span class="n">sampler</span><span class="o">=</span><span class="n">sampler</span><span class="p">)</span>
</pre></div>
</div>
<dl class="method">
<dt id="mindspore.dataset.SequentialSampler.add_child">
<code class="sig-name descname">add_child</code><span class="sig-paren">(</span><em class="sig-param">sampler</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.SequentialSampler.add_child" title="Permalink to this definition">¶</a></dt>
<dd><p>为给定采样器添加子采样器。子采样器接收父采样器输出数据作为输入，并应用其采样逻辑返回新的采样结果。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>sampler</strong> (Sampler) - 用于从数据集中选择样本的对象。仅支持内置采样器（DistributedSampler、PKSampler、RandomSampler、SequentialSampler、SubsetRandomSampler、WeightedRandomSampler）。</p></li>
</ul>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">sampler</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">SequentialSampler</span><span class="p">(</span><span class="n">start_index</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">num_samples</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sampler</span><span class="o">.</span><span class="n">add_child</span><span class="p">(</span><span class="n">ds</span><span class="o">.</span><span class="n">RandomSampler</span><span class="p">(</span><span class="n">num_samples</span><span class="o">=</span><span class="mi">2</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dataset</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">Cifar10Dataset</span><span class="p">(</span><span class="n">cifar10_dataset_dir</span><span class="p">,</span> <span class="n">sampler</span><span class="o">=</span><span class="n">sampler</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.SequentialSampler.get_child">
<code class="sig-name descname">get_child</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.SequentialSampler.get_child" title="Permalink to this definition">¶</a></dt>
<dd><p>获取给定采样器的子采样器。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">sampler</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">SequentialSampler</span><span class="p">(</span><span class="n">start_index</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">num_samples</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sampler</span><span class="o">.</span><span class="n">add_child</span><span class="p">(</span><span class="n">ds</span><span class="o">.</span><span class="n">RandomSampler</span><span class="p">(</span><span class="n">num_samples</span><span class="o">=</span><span class="mi">2</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">child_sampler</span> <span class="o">=</span> <span class="n">sampler</span><span class="o">.</span><span class="n">get_child</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.dataset.SequentialSampler.get_num_samples">
<code class="sig-name descname">get_num_samples</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.dataset.SequentialSampler.get_num_samples" title="Permalink to this definition">¶</a></dt>
<dd><p>返回采样器采集样本数量，如果存在子采样器，则子采样器计数可以是数值或None。这些条件会影响最终的采样结果。</p>
<p>下表显示了调用此函数的可能结果。</p>
<table class="colwidths-given docutils align-default">
<colgroup>
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
<col style="width: 25%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>子采样器</p></th>
<th class="head"><p>num_samples</p></th>
<th class="head"><p>child_samples</p></th>
<th class="head"><p>结果</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>T</p></td>
<td><p>x</p></td>
<td><p>y</p></td>
<td><p>min(x, y)</p></td>
</tr>
<tr class="row-odd"><td><p>T</p></td>
<td><p>x</p></td>
<td><p>None</p></td>
<td><p>x</p></td>
</tr>
<tr class="row-even"><td><p>T</p></td>
<td><p>None</p></td>
<td><p>y</p></td>
<td><p>y</p></td>
</tr>
<tr class="row-odd"><td><p>T</p></td>
<td><p>None</p></td>
<td><p>None</p></td>
<td><p>None</p></td>
</tr>
<tr class="row-even"><td><p>None</p></td>
<td><p>x</p></td>
<td><p>n/a</p></td>
<td><p>x</p></td>
</tr>
<tr class="row-odd"><td><p>None</p></td>
<td><p>None</p></td>
<td><p>n/a</p></td>
<td><p>None</p></td>
</tr>
</tbody>
</table>
<p><strong>返回：</strong></p>
<p>int，样本数，可为None。</p>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">sampler</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">SequentialSampler</span><span class="p">(</span><span class="n">start_index</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">num_samples</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">num_samplers</span> <span class="o">=</span> <span class="n">sampler</span><span class="o">.</span><span class="n">get_num_samples</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</div>


           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="mindspore.dataset.SubsetRandomSampler.html" class="btn btn-neutral float-right" title="mindspore.dataset.SubsetRandomSampler" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="mindspore.dataset.RandomSampler.html" class="btn btn-neutral float-left" title="mindspore.dataset.RandomSampler" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2021, MindSpore.

    </p>
  </div>
    
    
    
    Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    
    provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>